package com.speedata;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.speedata.uhftest.R;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author xuyan  张艳娇调试aw2013
 */
public class AW2013Activity extends AppCompatActivity implements View.OnClickListener {

    private Button bt1;
    private Button bt2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_aw2013);
        initView();
    }

    private void initView() {
        bt1 = findViewById(R.id.bt1);
        bt2 = findViewById(R.id.bt2);

        bt1.setOnClickListener(this);
        bt2.setOnClickListener(this);

//        String s = "()";
//        byte[] s2;
//
//        Log.d("byte", String.valueOf(s.getBytes()));
//        Toast.makeText(this, String.valueOf(s.getBytes()), Toast.LENGTH_SHORT).show();
//        List<byte[]> a = new ArrayList<>();

       // startActivity(new Intent("com.spd.action.SCAN.SERVICE"));
        startActivity(new Intent(AW2013Activity.this, Sp60TestActivity.class));
        finish();
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt1:
                //open("on");
                startActivity(new Intent(AW2013Activity.this, FlexboxTextActivity.class));
                break;
            case R.id.bt2:
                //open("off");
                startActivity(new Intent(AW2013Activity.this, MainActivity.class));
                break;
            default:
                break;
        }
    }

    private static BufferedWriter TorchFileWrite;

    /**
     * aw2013,
     *
     * @param str "on"  "off"
     */
    public static void open(String str) {
        File TorchFileName = new File("/sys/class/misc/aw2013/led2");
        try {
            TorchFileWrite = new BufferedWriter(new FileWriter(TorchFileName, false));
            TorchFileWrite.write(str);
            TorchFileWrite.flush();
            TorchFileWrite.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
